﻿using IdentityService.Domain.Aggregates.UserAccountAggregate;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace IdentityService.Infrastructure.EntitiesConfig
{
    public class UserAccountConfig : IEntityTypeConfiguration<UserAccount>
    {
        public void Configure(EntityTypeBuilder<UserAccount> builder)
        {
            builder.HasKey(it => it.Id);
            builder.Property(it => it.Id).ValueGeneratedNever();
            builder.Property("PasswordHash");
            builder.Property("SecurityStamp");

            builder.HasOne(it => it.UserInfo).WithOne().HasForeignKey<UserInfo>(it => it.UserAccountId);
            builder.HasMany(it => it.Roles).WithMany(it => it.UserAccounts);
            builder.HasMany(it => it.Claims).WithOne().HasForeignKey(it => it.UserAccountId).IsRequired();
        }
    }
}
